﻿package view.popup
{
    import com.core.*;
    import com.sh.game.global.*;
    import consts.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.bagN.*;
    import plugin.newvip.model.*;
    import pluginfw.nio.*;
    import uiresource.*;
    import view.*;
    import vo.*;

    public class JingYanZhuCtrl extends JingYanZhuUI implements IDialogUI
    {
        private var _state:int = 0;
        private var _index:int = 0;

        public function JingYanZhuCtrl()
        {
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(uiXML);
            this.initView();
            return;
        }// end function

        private function initView() : void
        {
            GlobalLayer.instance.root.stage.addEventListener(Event.RESIZE, this.resizeHandler);
            this.x = (GlobalLayer.instance.root.stage.stageWidth - this.width) / 2 + 50;
            this.y = (GlobalLayer.instance.root.stage.stageHeight - this.height) / 2;
            closeBtn.clickHandler = new Handler(this.close);
            btn1.addEventListener(MouseEvent.CLICK, this.lingquHandler);
            btn3.addEventListener(MouseEvent.CLICK, this.lingquHandler);
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_JHZ, btn3);
            return;
        }// end function

        protected function lingquHandler(event:MouseEvent) : void
        {
            var _loc_4:Output = null;
            var _loc_5:Array = null;
            ModelProxy.change("guide", "hide", GuideType.GUIDE_JHZ);
            var _loc_2:* = event.currentTarget as Button;
            var _loc_3:int = 1;
            if (_loc_2 == btn3)
            {
                _loc_3 = 2;
            }
            if (this._state > 0)
            {
                if (this._state > 2 && _loc_3 == 2)
                {
                    if (VipCheck.checkVip() <= 0)
                    {
                        DialogMgr.instance.open(AppDialog.XUFEI, [null]);
                        return;
                    }
                    _loc_4 = new Output();
                    _loc_4.writeVarInt(_loc_3, false);
                    ModelProxy.change("data", "recycle", 1);
                    PluginManager.instance.sendToBufferServer("bag", CMDBag.JuHunZhuLingQu, _loc_4);
                    ModelProxy.change("guide", "hide", GuideType.GUIDE_JHZ);
                    this.visible = false;
                }
                else
                {
                    _loc_4 = new Output();
                    _loc_4.writeVarInt(_loc_3, false);
                    ModelProxy.change("data", "recycle", 1);
                    PluginManager.instance.sendToBufferServer("bag", CMDBag.JuHunZhuLingQu, _loc_4);
                    ModelProxy.change("guide", "hide", GuideType.GUIDE_JHZ);
                    this.visible = false;
                }
            }
            else
            {
                if (_loc_3 == 2)
                {
                    if (VipCheck.checkVip() <= 0)
                    {
                        DialogMgr.instance.open(AppDialog.XUFEI, [null]);
                        return;
                    }
                }
                _loc_5 = [this._index, _loc_3];
                ModelProxy.change("data", "recycle", 1);
                PluginManager.instance.sendToServer("bag", CMDBag.UseJingYanZhu, _loc_5);
                ModelProxy.change("guide", "hide", GuideType.GUIDE_JHZ);
                this.visible = false;
            }
            return;
        }// end function

        public function close() : void
        {
            var _loc_1:Output = null;
            if (this._state == 1 || this._state == 2)
            {
                _loc_1 = new Output();
                _loc_1.writeVarInt(2, false);
                ModelProxy.change("data", "recycle", 1);
                PluginManager.instance.sendToBufferServer("bag", CMDBag.JuHunZhuLingQu, _loc_1);
            }
            ModelProxy.change("guide", "hide", GuideType.GUIDE_JHZ);
            this.visible = false;
            return;
        }// end function

        public function topDisplay() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            if (this.parent && this.parent.numChildren > 0)
            {
                _loc_1 = parent.getChildIndex(this);
                _loc_2 = parent.numChildren - 1;
                parent.setChildIndex(this, _loc_2);
            }
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_2:String = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            this.visible = true;
            this._state = int(param1.id);
            jytext.visible = false;
            if (param1.state > 0)
            {
                item.data = ItemObject.create(param1.itemObj);
                jytext.text = param1.exp + "/" + param1.exp + "经验";
                text1.text = "1倍领取,可领取" + param1.exp + "经验（免费）";
                text2.text = "2倍领取，可领取" + int(param1.exp) * 2 + "经验（vip）";
                cishuText.visible = false;
                text3.visible = false;
                chakanText.visible = false;
                item.mouseChildren = false;
                item.mouseEnabled = false;
                this._index = 0;
                labname.text = "聚魂珠";
            }
            else
            {
                item.data = ItemObject.create(param1[4]);
                labname.text = param1[4].name;
                _loc_2 = param1[4].bufferparam;
                _loc_3 = _loc_2.split("#");
                _loc_4 = _loc_3[0];
                jytext.text = _loc_4 + "/" + _loc_4 + "经验";
                text1.text = "1倍领取,可领取" + _loc_4 + "经验（免费）";
                text2.text = "2倍领取，可领取" + int(_loc_4) * 2 + "经验（vip" + _loc_3[3] + "）";
                _loc_5 = UserData.getOnlineData("jyz");
                text3.text = _loc_5 + "/10";
                item.mouseChildren = true;
                item.mouseEnabled = true;
                cishuText.visible = true;
                text3.visible = true;
                chakanText.visible = false;
                this._index = param1.index;
            }
            GuideView.getInstance().doGuide(GuideType.GUIDE_JHZ);
            this.topDisplay();
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.mouseDownHandler);
            return;
        }// end function

        private function mouseDownHandler(event:MouseEvent) : void
        {
            this.topDisplay();
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = (GlobalLayer.instance.root.stage.stageWidth - this.width) / 2 + 50;
            this.y = (GlobalLayer.instance.root.stage.stageHeight - this.height) / 2;
            return;
        }// end function

    }
}
